package com.yixing.tech.entity.po;

import com.yixing.tech.common.base.BasePO;
import com.yixing.tech.entity.entity.ObjStatus;
import com.yixing.tech.common.vo.s3.DictVO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.List;
import java.util.Map;

/**
 * @author yixing tech
 * at 2022/3/21
 * describe：
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class Obj extends BasePO {

    private String name;
    private String code;
    private String desc;
    private String status = ObjStatus.deft.name();
    private DictVO group;
    /**
     * default,process
     */
    private String type;
    private List<Attr> attrs;
    private List<AttrConfig> formConfig;
    private List<AttrConfig> addConfig;
    private List<AttrConfig> titleConfig;
    private List<AttrConfig> conditionConfig;
    private List<AttrConfig> previewConfig;
    private List<AttrConfig> appletTitleConfig;
    private List<AttrConfig> h5TitleConfig;
    private List<Button> buttonConfig;
    /**
     * 用于显示对象名称
     */
    private String agentAttrCode;

    /**
     * 前钩
     */
    private Boolean enablePreHook;
    /**
     * 后钩
     */
    private Boolean enableAfterHook;
    /**
     * 控件前端配置
     */
    Map config;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Attr {
        String type;
        String name;
        String desc;
        String code;
        /**
         * 是否生成索引
         */
        Boolean isIndex = false;
        Object reference;
        List<BackReference> backReferences;
        List filter;
        Object idleValue;
        String hintValue;
        String valueUnit;
        String valueFormat;
        Constraint constraint;
        Sort sortCondition;
        double sort;
        /**
         * 是否支持快速新增
         */
        Boolean fastInsertAble = true;
        /**
         * 是否启用合计
         */
        Boolean statisticsAble = false;
        /**
         * 控件前端配置
         */
        Map config;

        /**
         * 属性布局宽度
         */
        int gridWidth = 24;
        Double width;
        /**
         * 关联字段，默认是id
         */
        String relationalField;

        @Data
        @AllArgsConstructor
        @NoArgsConstructor
        public static class BackReference {
            String reference;
            String formulas;
        }

        @Data
        @AllArgsConstructor
        @NoArgsConstructor
        public static class Constraint {
            String reference;
            String formulas;
            String desc;
        }
    }
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class AttrConfig {
        String code;

        Boolean isNecessary;
        Boolean isUnique;
        Boolean isFocus;
        List<String> symbols;
        Object defaultValue;
        String reference;
        String key;
    }

    @Data
    @NoArgsConstructor
    public static class Button {
        String name;
        String code;
        String icon;
        String desc;
        String position;

        public Button(String name, String code, String icon, String position) {
            this.name = name;
            this.code = code;
            this.icon = icon;
            this.position = position;
        }
    }
}
